<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/views/common/includetag.jsp"%> 

<!DOCTYPE html>
<html lang="en_US">
    <head>
        <title><spring:message code="app.role.title" /></title>
    </head>
    <body>
        <div class="clearfix"></div>
        
		<div class="row back-top-title">
			<div class="col-md-12">
				<span><spring:message code="app.role.title" /></span>
			</div>
		</div>

        <form style="position:relative" id="splitPage" action="${contextPath}/role" method="POST" role="form" class="form-horizontal">
        	<div class="row">
				<div class="col-md-12">
					<div class="panel panel-white">
						<div class="panel-body">
							<div class="row">
								 <div class="col-md-12 space20">
									<a href="#none" class="btn btn-primary btn-add">
										<i class="fa fa-plus"></i>
										<spring:message code="app.role.action.add" />
									</a>
								 </div>
							</div>
							  
							<table id="dataTable" class="table table-striped table-bordered table-hover table-full-width">
                                  <thead>
                                      <tr>
                                          <th><spring:message code="app.common.title.serial" /></th>
                                          <th><spring:message code="app.role.title.name" /></th>
                                          <th><spring:message code="app.role.title.creator" /></th>
                                          <th><spring:message code="app.common.action.operate" /></th>
                                      </tr>
                                  </thead>
                                  <tbody>
                                      <c:forEach items="${PAGE_DATA}" var="role" varStatus="s">
                                          <tr data-id="${role.id}">
                                              <td><c:out value="${s.index + 1}" /></td>
                                              <td><c:out value="${role.name}" /></td>
                                              <td><c:out value="" /></td>
                                              <td>
                                                  <a href="${contextPath}/role/edit?id=${role.id}" class="btn btn-info btn-sm"><spring:message code="app.common.action.edit" /></a>
                                                  <a href="#none" class="btn btn-danger btn-sm btn-delete"><spring:message code="app.common.action.delete" /></a>
                                              </td>
                                          </tr>
                                      </c:forEach>
                                  </tbody>
                              </table>
					    </div>
					</div>
				</div>
			</div>
        </form>
        
        <script type="text/javascript">
	        $(function(){
	        	$('.btn-add').click(function(){
	        		location.href = '${contextPath}/role/add';
	        	});
	        	
	        	$('.btn-delete').click(function(){
	        		var roleId = $(this).parents('tr').attr('data-id');
	        		if(roleId){
	        			BootstrapDialog.confirm({
	        				title: '<spring:message code="app.role.title.delete" />',
	        	            message: '<spring:message code="app.role.title.delete.message" />',
	        	            btnCancelLabel: '<spring:message code="app.common.action.cancel" />',
	        	            btnOKLabel: '<spring:message code="app.common.action.confirm" />',
	        	            callback: function(f){
	        	            	if(f){
	        	            		$.ajax({
	        	        				type: 'POST',
	        	        				url: '${contextPath}/role/delete/exec',
	        	        				data: {'id': roleId},
	        	        				success: function(result){
	        	        					if(result){
	        	        						var r = $.parseJSON(result);
	        	        						if(r && r.resultCode == '000000'){
	        	        							location.href = contextPath + '/role';
	        	        						}
	        	        					}
	        	        				}
	        	        			});
	        	            	}
	        	            }
	        			});
	        		}
	        	});
	        });
	    </script>
    </body>
</html>